package wineshop.domain.market;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Version;

import wineshop.domain.general.Address;

/**
 * The persistent class for the order database table.
 * 
 */
@Entity
public class Purchase implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name = "order_seq", sequenceName = "wineshop_seq", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_seq")
	long id;

	@Version
	Integer version;

	@ManyToOne
	@JoinColumn(name = "address")
	private Address address;

	private Timestamp date;

	@OneToOne
	@JoinColumn(name = "item")
	private Item item;

	@ManyToOne
	@JoinColumn(name = "creditcard")
	private Creditcard creditcard;

	@ManyToOne
	@JoinColumn(name = "customer")
	private Customer customer;

	Purchase() {
	}

	Purchase(Item wine, Date time, Customer customer, Creditcard card,
			Address addressDelivery) {
		this.item = wine;
		wine.setPurchase(this);
		this.date = new Timestamp(time.getTime());
		this.customer = customer;
		this.creditcard = card;
		this.address = addressDelivery;
	}

	public Address getAddress() {
		return this.address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public Timestamp getDate() {
		return this.date;
	}

	public void setDate(Timestamp date) {
		this.date = date;
	}

	public Item getItem() {
		return this.item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	public Creditcard getCreditcard() {
		return this.creditcard;
	}

	public void setCreditcard(Creditcard creditcard) {
		this.creditcard = creditcard;
	}

	public Customer getCustomer() {
		return this.customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

}